var Memcached = require('memcached')
var utils = require('./util/utils')

var sysConf = global.sysConfig;
var mem = new Memcached(sysConf.memcached.host)

exports.set = function (key, value, callback, lifetime){
	if(!key)
		return false;
	if(typeof value == 'undefined')
		value = '';
	if(typeof callback != 'function'){
		callback = function(){}
	}
	if(!lifetime || !parseInt(lifetime))
		lifetime = utils.parseTimeConf(sysConf.memcached.lifetime, 1);
	mem.set(key, value, lifetime, callback)
}

exports.get = function (key, callback){
	if(!key)
		return false;
	if(typeof callback != 'function'){
		callback = function(){}
	}
	mem.get(key, callback)
}

exports.del = function (key, callback){
	if(!key)
		return false;
	if(typeof callback != 'function'){
		callback = function(){}
	}
	mem.del(key, callback)
}

exports.flush = function (callback){
	mem.flush(callback);
}